package com.example.taximeter.service.impl;

import com.example.taximeter.bean.ReturnInfo;
import com.example.taximeter.bean.Search;
import com.example.taximeter.bean.UpdateRecord;
import com.example.taximeter.mapper.UpdateRecordMapper;
import com.example.taximeter.service.UpdateRecordService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 升级记录
 */
@Service
public class UpdateRecordServiceImpl implements UpdateRecordService {


    private UpdateRecordMapper updateRecordMapper;

    @Autowired
    public UpdateRecordServiceImpl(UpdateRecordMapper updateRecordMapper){
        this.updateRecordMapper = updateRecordMapper;
    }

    @Override
    public ReturnInfo findSearchAll(Integer pageNum, Integer pageSize, UpdateRecord updateRecord) {
        if(!pageNum.equals(0)||!pageSize.equals(0)){
            PageHelper.startPage(pageNum, pageSize);
        }
        Integer pagetotal = 0;
        Long total = 0L;
        List<UpdateRecord> updateRecords = updateRecordMapper.findUpdateRecordAll(updateRecord);
        PageInfo<UpdateRecord> pageInfo = new PageInfo<>(updateRecords);
        if(updateRecords.size()!=0){
            pagetotal = pageInfo.getPages();
            total = pageInfo.getTotal();
        }
        return ReturnInfo.info5(pagetotal,total,pageInfo.getList());
    }
}
